package com.szr.leex.service.impl.debtor;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.szr.leex.dao.BaseDao;
import com.szr.leex.dao.debtor.DebtorInfoDao;
import com.szr.leex.po.debtor.DebtorInfo;
import com.szr.leex.service.debtor.DebtorInfoService;
import com.szr.leex.service.impl.BaseServiceImpl;

/**
 * 场景方信息service impl
 * Created by WangChen on 2018/8/25 11:47.
 */
@Service
public class DebtorInfoServiceImpl extends BaseServiceImpl<DebtorInfo, String> implements DebtorInfoService {

    // Field injection is not recommended
    // 参考
    // https://blog.csdn.net/loongshawn/article/details/80005309
    // https://stackoverflow.com/questions/39890849/what-exactly-is-field-injection-and-how-to-avoid-it
    // 使用该种依赖注入(Field injection)弊端
    // 1.该类的依赖和容器强耦合，不能脱离容器使用
    // 2.该类在单元测试的时候，不能绕过反射进行实例化。必须通过依赖容器才能实例化，这更像是集成测试
    // 3.实际的依赖被隐藏在外面，不是在构造方法或者其他方法里面发射的
    // 4.过多的field injection可能会违背单一原则
    // 5.不能使用属性注入的方式构建不可变对象
    @Autowired
    private DebtorInfoDao debtorInfoDao;

    @Override
    public BaseDao<DebtorInfo, String> getBaseDao() {
        return debtorInfoDao;
    }

    @Override
    public List<DebtorInfo> list(){
        return debtorInfoDao.findAll();
    }

    @Override
    public DebtorInfo add(DebtorInfo debtorInfo) {
        return debtorInfoDao.save(debtorInfo);
    }

    @Override
    public DebtorInfo findByOrgCode(String orgCode) {
        return debtorInfoDao.findByOrgCode(orgCode);
    }

    @Override
    public Page ssss(String orgCode, Pageable pageable) {
//        return debtorInfoDao.findDtoPage(orgCode, pageable);
        return null;
    }
}
